﻿using _01_Tower4._0.GameFrame;
using _01_Tower4._0.Scene;
using _01_Tower4._0.Tool;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01_Tower4._0.CharacterBase.EnemyType
{
    internal class EnemyGoblin : Enemy
    {
        public EnemyGoblin(string name, int hp, int maxHp, int mp, int maxMp, int atk, int def, Pos pos, Map map, string display,ConsoleColor color, SceneMap1 scene) : base(name, hp, maxHp, mp, maxMp, atk, def, pos, map, display,color, scene)
        {
        }

        void Move(int offsetX, int offsetY)
        {
            map.SetType(Pos, Map.Type.None);
            backup = Pos;
            Pos temp = Pos;
            Utility.MyPrint(" ", Pos.x + map.offsetX, Pos.y + map.offsetY);
            temp.x += offsetX;
            temp.y += offsetY;
            Pos = temp;
            if (map.GetType(Pos) == Map.Type.Wall ||
                map.GetType(Pos) == Map.Type.Map1Key0 ||
                map.GetType(Pos) == Map.Type.Map2Key0 ||
                map.GetType(Pos) == Map.Type.Map2Key1 ||
                map.GetType(Pos) == Map.Type.Map2Button0 ||
                map.GetType(Pos) == Map.Type.Map1Step0 ||
                map.GetType(Pos) == Map.Type.Map2Step0 ||
                map.GetType(Pos) == Map.Type.Map2Step1 ||
                map.GetType(Pos) == Map.Type.Map3Step0 ||
                map.GetType(Pos) == Map.Type.TrapWall ||
                map.GetType(Pos) == Map.Type.Tool)
            {
                Pos = backup;
            }
            map.SetType(Pos, Map.Type.MonGoblin);
        }

        public void Update()
        {
            if (IsDialoging || IsCombating) return;

            currentTime = DateTime.Now.Ticks;
            if (currentTime - lastTime > Game.rand.Next(1000, 3000) * 10000)
            {
                Move(Game.rand.Next(-1, 2), Game.rand.Next(-1, 2));
                lastTime = currentTime;
            }
        }

        public override void OnDead()
        {
            base.OnDead();
            // 删除逻辑
            //map.SetType(Pos, Map.Type.MonSlime);

            scene.goblin.Remove(this);
            Utility.MyPrint("  ", Pos.x + map.offsetX, Pos.y + map.offsetY);
        }
    }
}
